// 菜单设置
function startMenuSetting() {
    var arr = getCheckedIdArr();
    if (!arr.length > 0) {
        layer.alert('请选择职位！',{icon: 5});
        return;
    }
    openPage('权限配置', menuSettingUrl, function () {
        ajaxPost(ajaxMenuListUrl, {}, function (result) {
            var setting = {
                check: {
                    enable: true
                },
                data: {
                    simpleData: {
                        enable: true
                    }
                }
            };

            var zNodes = eval(result.data);

            var treeObj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
            // 默认展开全部节点
            treeObj.expandAll(true);
            // 显示角色已拥有的菜单
            ajaxPost(ajaxRoleMenu, {'roleId': arr[0]}, function (result) {
                for (var i = 0; i < result.data.length; i++) {
                    var node = treeObj.getNodeByParam("id", result.data[i].menuId, null);
                    if (node != null) {
                        treeObj.checkNode(node, true, true);
                    }
                }
            })
        })
    }, function () {
        startSaveSetting(arr[0]);
    });
}

// 保存设置
function startSaveSetting(roleIds) {
    var arr = getZtreeCheckedIdArr();
    if (!arr.length > 0) {
        layer.alert('请选择权限！',{icon: 5});
        return;
    }
    var menuIds = arr.join(",");
    ajaxPost(ajaxSaveSettingUrl, {"roleIds": roleIds, "menuIds": menuIds}, function (result) {
        layer.close(layer.index);
        layer.msg(result.msg, {time: 1000}, function () {
            startRefresh();
        });
    });
}